<%= render :partial => "/tr8n/admin/common/header" %>
<%= render :partial => "tabs" %>
<%= tr8n_will_filter(@translators) %>

<%= link_to_function("+ Register new translator", "Tr8n.UI.Lightbox.show('/tr8n/admin/translator/lb_register', {height:150})") %>
 | 
<%= link_to("Update translators stats", {:action => :update_stats}, :confirm => "Are you sure you want to run this opperation?")%>

<%= form_tag("", :id => "tr8n_form") do %>
  <%= hidden_field_tag(:type, "translator") %>
  <%= will_filter_table_tag(@translators, :columns => [
    [:icn, image_tag("tr8n/icons/user.png"), :title => "", :style => "width:12px;"],
    [:checkbox, :ids],
    :id,
    [:name, lambda{|translator|
       link_to(translator.name, :action => :view, :id => translator.id) 
    }],
    :country_code, 
    [:admin, lambda{|translator|
      translator.admin?  
    }, 'text-align:right'],
    [:level, lambda{|translator|
      if translator.admin?
        "<span style='color:red'>#{translator.title}</span>".html_safe
      elsif translator.manager?
        "<span style='color:brown'>#{translator.title}</span>".html_safe
      else
        translator.title
      end     
    }, 'text-align:right'],
    [:blocked, lambda{|translator|
      html = []
      if translator.blocked?
        html << "<span style='color:red'>"
      else
        html << "<span style='color:green'>"
      end     
      html << translator.blocked?
      html << "</span>"
      html.join("").html_safe
    }, 'text-align:right'],
    [:rank, lambda{|translator|
      translator.rank ? (translator.rank * 100).to_i / 100.0 : 0
    }, 'text-align:right'], 
    [:translation_count, lambda{|translator|
      link_to(translator.total_metric.total_translations || 0, "/tr8n/admin/translation?wf_c0=translator_id&wf_o0=is&wf_v0_0=#{translator.id}")
    }, 'text-align:right'],
    [:vote_count, lambda{|translator|
      html = []
      html << (translator.total_metric.total_votes || 0)
      html << " (<span style='color:green'>"
      html << (translator.total_metric.positive_votes || 0) 
      html << "</span>/<span style='color:red'>"
      html << (translator.total_metric.negative_votes || 0)
      html << "</span>)"
      html.join("").html_safe			
    }, 'text-align:right'],
    [:actions, lambda{|translator|
      tr8n_actions_tag([
        link_to_function("Delete", "deleteObjects('#{translator.id}')")
      ])
    }, 'text-align:right;white-space:nowrap;']
  ]) %>
<% end %>

<%= will_filter_actions_bar_tag(@translators, [
  ['Delete Selected Translators', 'deleteObjects()'],
  ['Add To Component', 'addSelectedTranslatorsToComponent()'],
]) %>

<%= render :partial => "/tr8n/admin/common/footer" %>

<script>
  function getSelectedTranslators() {
    var i=0;
    var checkbox = Tr8n.element('wf_check_' + i);
    var translators = [];
    while (checkbox) {
      if (checkbox.checked) {
        translators.push(checkbox.value);
      }
      checkbox = Tr8n.element('wf_check_' + (++i));
    }
    return translators; 
  }

  function addSelectedTranslatorsToComponent() {
    var translators = getSelectedTranslators();
    if (translators.length == 0) {
      alert('At least one translator must be selected.');
      return;
    }
    Tr8n.UI.Lightbox.show('/tr8n/admin/applications/lb_add_to_component?translators=' + translators, {height:400});
  }  
</script>
